//Installing packages
ssc install reghdfe, replace
ssc install outreg2, replace


//Please set the working directory to "Replication"
* For example:
*cd "~/Dropbox/Research Projects/Repression/Replication"


use "data/disguise.dta", clear

//Standardizing outcome variables

egen stddissent = std(dissent)
egen stdsupportdis = std(supportdis)
egen stdsupportrep = std(supportrep)
egen stdstreisandpol = std(streisandpol)
egen stdstreisand = std(streisand)
egen stdselfcensorship = std(selfcensorship)
egen stdselfcensor = std(selfcensor)
egen stdmorality = std(morality)
egen stdattitude = std(attitude)
egen stdaction = std(action)

//Setting up macros

global covarbal "female age edulv minority religious married work work_public work_report ccp income eng socialmedia class"

global treat "control taxevasion prostitution"

global treatcensor "political taxevasion prostitution"

global covar "female age edulv minority religious married work work_public work_report ccp income eng socialmedia class"

//Generating a table for plotting Figure 2 (a), (b), and (c)
cap erase "output/plotstd_attrepdis.txt"
qui foreach var of varlist stdsupportdis stdsupportrep stddissent{	
	reghdfe `var' $treat $covar, vce(r) a(sprov_1)
	outreg2 using "output/plotstd_attrepdis.txt", text dec(3) nocons keep($treat) sideway noas nopa nor2 noobs nonotes		
}

//Generating a table for plotting Figure 3
qui reghdfe stdmorality $treat $covar, vce(r) a(sprov_1)
	outreg2 using "output/plotstd_moral.txt", text dec(3) nocons keep($treat) sideway noas nopa nor2 noobs nonotes replace
	
//Table 2 and Table A5: Self-censorship
cap erase "output/outbeh.xls"
cap erase "output/outbeh.txt"

sum moral, detail
 
qui reghdfe selfcensor $treatcensor $covar, vce(r) a(sprov_1)
    qui outreg2 using "output/outbeh.xls", excel dec(3) replace
qui reghdfe selfcensor $treatcensor $covar if dsocritic > 1, vce(r) a(sprov_1)
    qui outreg2 using "output/outbeh.xls", excel dec(3)
qui reghdfe selfcensor $treatcensor $covar if dsocritic <= 1, vce(r) a(sprov_1)
    qui outreg2 using "output/outbeh.xls", excel dec(3)
qui reghdfe selfcensor $treatcensor $covar if dsocritic > 1 & moral <= 127, vce(r) a(sprov_1)
    qui outreg2 using "output/outbeh.xls", excel dec(3)
qui reghdfe selfcensor $treatcensor $covar if dsocritic > 1 & moral > 127, vce(r) a(sprov_1)
    qui outreg2 using "output/outbeh.xls", excel dec(3)





*********************Appendix Tables and Figures*************************


//Table A1: Balance check
cap erase "output/bal.xls"
cap erase "output/bal.txt"
qui foreach var of varlist $covarbal {
	reg `var' $treat, r
	test $treat
	outreg2 using "output/bal.xls", excel dec(3) addstat(F test, e(p))
}

//Table A2: Effects of anonymity on outcomes
global outcome1 "supportdis supportrep dissent selfcensor"
cap erase "output/anonymity.xls"
cap erase "output/anonymity.txt"
qui foreach var of varlist $outcome1 {
	qui reghdfe `var' anonymity $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/anonymity.xls", excel dec(3) 
}

//Table A3: Effects of crime charges on outcomes (standardized, read-more-info sample)
qui reghdfe stdsupportdis $treat $covar if readmore == 1, vce(r) a(sprov_1)
qui outreg2 using "output/mainread.xls", excel dec(3) replace
qui reghdfe stdsupportrep $treat $covar if readmore == 1, vce(r) a(sprov_1)
qui outreg2 using "output/mainread.xls", excel dec(3)
qui reghdfe stddissent $treat $covar if readmore == 1, vce(r) a(sprov_1)
qui outreg2 using "output/mainread.xls", excel dec(3)

//Generating a table for plotting Figure A2 (a), (b), and (c)
cap erase "output/plot_attrepdis.txt"
qui foreach var of varlist supportdis supportrep dissent{	
	reghdfe `var' $treat $covar, vce(r) a(sprov_1)
	outreg2 using "output/plot_attrepdis.txt", text dec(3) nocons keep($treat) sideway noas nopa nor2 noobs nonotes		
}

//Table A4. Effects of crime charges on outcomes (standardized)
    qui reg stdsupportdis $treat, r
	qui outreg2 using "output/mainstd.xls", excel dec(3) replace
    qui reg stdsupportdis $treat $covar, r
    qui outreg2 using "output/mainstd.xls", excel dec(3)
	qui reghdfe stdsupportdis $treat $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/mainstd.xls", excel dec(3)
	
    qui reg stdsupportrep $treat, r
	qui outreg2 using "output/mainstd.xls", excel dec(3)
    qui reg stdsupportrep $treat $covar, r
    qui outreg2 using "output/mainstd.xls", excel dec(3)
	qui reghdfe stdsupportrep $treat $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/mainstd.xls", excel dec(3)

    qui reg stddissent $treat, r
	qui outreg2 using "output/mainstd.xls", excel dec(3)
    qui reg stddissent $treat $covar, r
    qui outreg2 using "output/mainstd.xls", excel dec(3)
	qui reghdfe stddissent $treat $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/mainstd.xls", excel dec(3)
	
//Table A5: Self-censorship, see "output/outbeh.xls" generated above

//Table A6: Seeking information on KOL
    qui reg streisand $treat, r
	qui outreg2 using "output/streisand.xls", excel dec(3) replace
    qui reg streisand $treat $covar, r
    qui outreg2 using "output/streisand.xls", excel dec(3)
	qui reghdfe streisand $treat $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/streisand.xls", excel dec(3)
	
    qui reg streisandpol $treat, r
	qui outreg2 using "output/streisand.xls", excel dec(3)
    qui reg streisandpol $treat $covar, r
    qui outreg2 using "output/streisand.xls", excel dec(3)
	qui reghdfe streisandpol $treat $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/streisand.xls", excel dec(3)

//Table A7: Perceived morality of the critic (standardized)
qui reg stdmorality $treat, r
    qui outreg2 using "output/stdmorality.xls", excel dec(3) replace
qui reg stdmorality $treat $covar, r
    qui outreg2 using "output/stdmorality.xls", excel dec(3)
qui reghdfe stdmorality $treat $covar, vce(r) a(sprov_1)
    qui outreg2 using "output/stdmorality.xls", excel dec(3)


//Table A8: Committed Crime
	qui reg crimecmt $treat, r
	qui outreg2 using "output/committed.xls", excel dec(3) replace
    qui reg crimecmt $treat $covar, r
    qui outreg2 using "output/committed.xls", excel dec(3)
	qui reghdfe crimecmt $treat $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/committed.xls", excel dec(3)


//Figure A2: Plot WVS Judicial Confidence
preserve
use "data/wvs_jud.dta", clear // World Value Survey, Wave 7, China
gen judtrust = 5-Q70 if Q70 > 0
label define judtrustlab 1 "None at all" 2 "Not very much" 3 "Quite a lot" 4 "A great deal", replace
label values judtrust judtrustlab
graph bar if Q70 >= 0 , over(judtrust) blabel(bar, position(above) format(%9.2f) size(medsmall)) ///
      plotregion(style(line) lcolor(black)) ytitle("Percent",size(large)) ///
      bar(1, color(gray)) title("Confidence in Judicial System (WVS Wave 7, China)")
graph export "graphs/fg_supportjud.png", replace

restore

//Table A9: Interaction effects of crime charges and confession
cap erase "output/confession.xls"
cap erase "output/confession.txt"
qui foreach var of varlist $outcome1 {
	qui reghdfe `var' control##confession taxevasion##confession prostitution##confession $covar, vce(r) a(sprov_1)
	qui outreg2 using "output/confession.xls", excel dec(3)
}

//Table A11: Manipulation check
log using "output/tb_manipulation.log", replace
tab treatment manipulation 
log close
translate "output/tb_manipulation.log" "output/tb_manipulation.txt", translator(smcl2txt) replace

//Table A12: Main results: manipulation check passed
gen manipulation1 = manipulation + 1

qui reg supportdis $treat if treatment == manipulation1, r
qui outreg2 using "output/manipulation.xls", excel dec(3) replace
qui reg supportdis $treat $covar if treatment == manipulation1, r
qui outreg2 using "output/manipulation.xls", excel dec(3)
qui reghdfe supportdis $treat $covar if treatment == manipulation1, vce(r) a(sprov_1)
qui outreg2 using "output/manipulation.xls", excel dec(3)
	
qui reg supportrep $treat if treatment == manipulation1, r
qui outreg2 using "output/manipulation.xls", excel dec(3)
qui reg supportrep $treat $covar if treatment == manipulation1, r
qui outreg2 using "output/manipulation.xls", excel dec(3)
qui reghdfe supportrep $treat $covar if treatment == manipulation1, vce(r) a(sprov_1)
qui outreg2 using "output/manipulation.xls", excel dec(3)

qui reg dissent $treat if treatment == manipulation1, r
qui outreg2 using "output/manipulation.xls", excel dec(3)
qui reg dissent $treat $covar if treatment == manipulation1, r
qui outreg2 using "output/manipulation.xls", excel dec(3)
qui reghdfe dissent $treat $covar if treatment == manipulation1, vce(r) a(sprov_1)
qui outreg2 using "output/manipulation.xls", excel dec(3)
